import Dialog from "./index.vue";
import Vue from "vue";
import { deepClone } from "@/utils/index";
// 使用构造器创建一个包含组件选项的对象
let myDialog = Vue.extend(Dialog);
let instance;

let openDialog = function (options = {}) {
  let params = options.data ? deepClone(options.data) : Object.create(null);
  const { dialogWidth, dialogTitle, components, beforeClose } = options;
  // 将传入的数据和创建的对象合并，生成新实例并挂载
  instance = new myDialog({
    data: {
      parent: this,
      dialogTitle,
      dialogWidth,
      ...params,
      beforeClose,
    },
    components: {
      DialogContent: components,
    },
  });
  // 挂载
  document.body.appendChild(instance.$mount().$el);
};

export default openDialog;
